package cn.mason.echarts;

import com.baomidou.kisso.SSOHelper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@SpringBootApplication
@Controller
public class EchartsApplication {

	@RequestMapping("/index")
	public String index(HttpServletRequest request){
		String id = SSOHelper.getSSOToken(request).getId();
		if(id==null||"".equals(id)){
			return "login";
		}else{
			return "index";
		}
	}

	@RequestMapping("/3D-scatter")
	public String scatter3D(){
		return "3D-scatter";
	}

	@RequestMapping("/2D-scatter")
	public String scatter2D(){
		return "2D-scatter";
	}

	@RequestMapping("/pie")
	public String pie(){
		return "pie";
	}

    @RequestMapping("/graph")
    public String graph(){
        return "graph";
    }

    @RequestMapping("/line")
    public String line(){
        return "line";
    }

    @RequestMapping("/bar")
    public String bar(){
        return "bar";
    }

	@RequestMapping(value = "/drawMap",method = RequestMethod.POST)
	@ResponseBody
	public String drawMap(@RequestParam("data")MultipartFile data){
		try {
			InputStream inputStream=data.getInputStream();
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(inputStream));
			String result = "";
			while (true) {
				String str = reader.readLine();
				if(str!=null){
					result+=str;
				} else
					break;
			}
			return  result;
		}catch (IOException e){
			return null;
		}
	}

	public static void main(String[] args) {
		SpringApplication.run(EchartsApplication.class, args);
	}
}
